home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 24
/
Amiga Format AFCD24 (Feb 1998, Issue 108).iso
/
-seriously_amiga-
/
shareware
/
programming
/
other
/
apic
/
examples
/
84emu.lst
< prev
next >
Wrap
File List
|
1998-01-05
|
20KB
|
500 lines
#PIC V1.0 (c)1997 J.Petroglou LIST FILE
#file: dh2:IDE/APICforAMINET/APIC/examples/84EMU.asm
#date: Sun Dec 14 20:58:42 1997
#pic : PIC16C57
ADDR CODE SRCLINE SOURCECODE
0000 000001
0000 000002
0000 000003 ;
0000 000004 ; This 16c57 prog can emulate an 16c84 using PICSim. PICEmu
0000 000005 ; is connected direct with the RS232 port. (using 10K for
0000 000006 ; the AMIGA TXD line). PortA and PortB are used for emulating
0000 000007 ; the 16c84. portC is used for the serial connection. The
0000 000008 ; communication speed is 38400 Baud @ 11.0592 Mhz clock.
0000 000009 ;
0000 000010 ;
0000 000011 ; © Dirk Duesterberg, 14.12.1997
0000 000012 ;
0000 000013 ; duesterb@unixserv.rz.fh-hannover.de
0000 000014 ; http://linux.rz.fh-hannover.de/~duesterb
0000 000015 ;
0000 000016
0000 000017
0000 000018
0000 000019
0000 000020 ;commands = 0x5x
0000 000021 ;
0000 000022 ;18 pin PIC Emulator soft for 16c57
0000 000023 ;
0000 000024 ;command0 = set tris RA, 1->, 1->
0000 000025 ;command1 = set tris RB, 1->, 1->
0000 000026 ;
0000 000027 ;command4 = write RA, 1->, 1<-, 1->
0000 000028 ;command5 = write RB, 1->, 1<-, 1->
0000 000029 ;
0000 000030 ;command8 = read RA, 1->, 1<-
0000 000031 ;command9 = read RB, 1->, 1<-
0000 000032 ;
0000 000033 ;
0000 000034
0000 000035
0000 000036
0000 000037 list p=16c57
0000 000038
0000 000039
0000 000040
0000 000041
0000 000042
0000 000043 #define c 03h,0 ;carry bit
0000 000044 #define dc 03h,1 ;digit carry bit
0000 000045 #define z 03h,2 ;zero bit
0000 000046 #define pd 03h,3 ;power down bit
0000 000047 #define to 03h,4 ;time out bit
0000 000048 #define pa0 03h,5 ;page select bit (for '56 and '57 only)
0000 000049 #define pa1 03h,6 ;page select bit (for '57 only)
0000 000050
0000 000051
0000 000052 pc = 02h ;program counter
0000 000053
0000 000054 RA = 05h ;port a
0000 000055 RB = 06h ;port b
0000 000056 RC = 07h
0000 000057
0000 000058
0000 000059
0000 000060 #define RXD RC,1
0000 000061 #define TXD RC,2
0000 000062
0000 000063 #define beta
0000 000064
0000 000065 ram = 08h ;begin of ram adress
0000 000066
0000 000067 CBLOCK ram ;constant block beginning
0000 000068
0000 000068
0000 000069 count0
0000 000070 count1
0000 000071
0000 000071
0000 000072 delaycntr
0000 000073 bitcntr
0000 000074 serdata
0000 000075 serbuf
0000 000076 charcounter
0000 000077 ENDC ;end of block
0000 000078
0000 000079
0000 000080
0000 000081
0000 000082 clockspeed = .11059200 ;clockspeed is 11.0592 Mhz
0000 000083 baudrate = .38400 ;19200 ;enter baudrate here
0000 000084
0000 000085
0000 000086 delay = (clockspeed/.4/baudrate-.12)/.4 ;value for baudrate, 12 cycles fixed, 4 cycles delay
0000 000087
0000 000088
0000 0C02 000089 start movlw 02h
0001 0007 000090 tris RC
0002 0C00 000091 movlw 0
0003 0027 000092 movwf RC
0004 000093
0004 000094
0004 02E8 000095 :loop decfsz count0 ;power up timer
0005 0A04 000096 goto :loop
0006 02E9 000097 decfsz count1
0007 0A04 000098 goto :loop
0008 000099
0008 000100
0008 000101
0008 0C52 000102 movlw 'R'
0009 002C 000103 movwf serdata
000A 0987 000104 call send_byte
000B 000105
000B 000106
000B 000107
000B 0C53 000108 movlw 'S'
000C 002C 000109 movwf serdata
000D 0987 000110 call send_byte
000E 000111
000E 000112
000E 000113
000E 000114
000E 0C54 000115 movlw 'T'
000F 002C 000116 movwf serdata
0010 0987 000117 call send_byte
0011 000118
0011 000119
0011 000120
0011 000121
0011 000122
0011 000123
0011 0CF0 000124 loop movlw 0f0h
0012 014C 000125 andwf serdata,w
0013 0F50 000126 xorlw 050h ;data = 50h ?
0014 0743 000127 btfss z
0015 0A11 000128 goto loop ;no match
0016 000129
0016 000130
0016 020C 000131 movf serdata,w
0017 0E0F 000132 andlw 0fh ;clear upper nibble
0018 01E2 000133 addwf pc ;jumptable
0019 000134
0019 0A29 000135 goto command0 ;write RA tristate register
001A 0A2D 000136 goto command1 ;write RB tristate register
001B 0A31 000137 goto command2 ;write RC tristate register (not used)
001C 0A32 000138 goto command3
001D 0A33 000139 goto command4 ;write RA latch
001E 0A3A 000140 goto command5 ;write RB latch
001F 0A41 000141 goto command6 ;write RC latch (not used)
0020 0A41 000142 goto command7
0021 0A42 000143 goto command8 ;read RA pins
0022 0A46 000144 goto command9 ;read RB pins
0023 0A4A 000145 goto commandA ;read RC pins
0024 0A4E 000146 goto commandB
0025 0A4E 000147 goto commandC
0026 0A4E 000148 goto commandD
0027 0A4E 000149 goto commandE
0028 0A4F 000150 goto commandF ;version info
0029 000151
0029 000152
0029 000153
0029 000154
0029 000155
0029 0997 000156 command0 call receive_byte
002A 020C 000157 movf serdata,w
002B 0005 000158 tris RA
002C 0A11 000159 goto loop
002D 000160
002D 000161
002D 0997 000162 command1 call receive_byte
002E 020C 000163 movf serdata,w
002F 0006 000164 tris RB
0030 0A11 000165 goto loop
0031 000166
0031 000167
0031 000168
0031 0A00 000169 command2 goto start
0032 0A00 000170 command3 goto start
0033 000171
0033 000172
0033 0205 000173 command4 movf RA,w
0034 002C 000174 movwf serdata
0035 0987 000175 call send_byte ;send read data back (ACKnowledge)
0036 000176
0036 0997 000177 call receive_byte
0037 020C 000178 movf serdata,w
0038 0025 000179 movwf RA
0039 000180
0039 0A11 000181 goto loop
003A 000182
003A 000183
003A 000184
003A 000185
003A 0206 000186 command5 movf RB,w
003B 002C 000187 movwf serdata,w
003C 0987 000188 call send_byte ;send read data back (ACKnowledge)
003D 000189
003D 0997 000190 call receive_byte
003E 020C 000191 movf serdata,w
003F 0026 000192 movwf RB
0040 000193
0040 0A11 000194 goto loop
0041 000195
0041 000196
0041 000197
0041 000198 command6
0041 000199
0041 0A00 000200 command7 goto start
0042 000201
0042 0205 000202 command8 movf RA,w ;read port
0043 002C 000203 movwf serdata
0044 0987 000204 call send_byte ;send read data back (ACKnowledge)
0045 0A00 000205 goto start
0046 000206
0046 0206 000207 command9 movf RB,w ;read port
0047 002C 000208 movwf serdata
0048 0987 000209 call send_byte ;send read data back (ACKnowledge)
0049 0A11 000210 goto loop
004A 000211
004A 0CAA 000212 commandA movlw 0aah
004B 002C 000213 movwf serdata
004C 0987 000214 call send_byte
004D 0A11 000215 goto loop
004E 000216
004E 000217
004E 000218
004E 000219
004E 000220 commandB
004E 000221 commandC
004E 000222 commandD
004E 0A00 000223 commandE goto start
004F 000224
004F 006E 000225 commandF clrf charcounter
0050 0958 000226 :loop call string
0051 0EFF 000227 andlw 0ffh
0052 0643 000228 btfsc z
0053 0A11 000229 goto loop ;return to start if zero byte
0054 000230
0054 002C 000231 movwf serdata ;move character to serial buffer
0055 0987 000232 call send_byte
0056 02AE 000233 incf charcounter ;next character
0057 0A50 000234 goto :loop
0058 000235
0058 000236
0058 000237
0058 000238
0058 000239
0058 020E 000240 string movf charcounter,w
0059 01E2 000241 addwf pc,f ;jump table with string followed by a zero byte.
005A 000242
005A 000243
005A 000245
beta Version
005A 000249
005A 0850 000250 retlw "PIC 16c84 EMU beta version, bla, bla, bla",0ah,0ah ;string, two linefeeds
005B 0849 000250
005C 0843 000250
005D 0820 000250
005E 0831 000250
005F 0836 000250
0060 0863 000250
0061 0838 000250
0062 0834 000250
0063 0820 000250
0064 0845 000250
0065 084D 000250
0066 0855 000250
0067 0820 000250
0068 0862 000250
0069 0865 000250
006A 0874 000250
006B 0861 000250
006C 0820 000250
006D 0876 000250
006E 0865 000250
006F 0872 000250
0070 0873 000250
0071 0869 000250
0072 086F 000250
0073 086E 000250
0074 082C 000250
0075 0820 000250
0076 0862 000250
0077 086C 000250
0078 0861 000250
0079 082C 000250
007A 0820 000250
007B 0862 000250
007C 086C 000250
007D 0861 000250
007E 082C 000250
007F 0820 000250
0080 0862 000250
0081 086C 000250
0082 0861 000250
0083 080A 000250
0084 080A 000250
0085 000251
0085 000253
0085 000257
0085 000259
0085 000261
0085 000262
0085 080D 000263 retlw 0dh,0 ;one cr, Zerobyte => stop sending
0086 0800 000263
0087 000264
0087 000265
0087 000266
0087 000267
0087 000268
0087 000269
0087 000270
0087 000271
0087 0547 000272 send_byte bsf TXD ;set TXD line, dirct connection
0088 0C08 000273 movlw 8h ;Eight bits in a byte.
0089 002B 000274 movwf bitcntr
008A 000275
008A 09A6 000276 call bitdelay ;Start bit. ((delay * 4) + 4) cycles
008B 000277
008B 032C 000278 xmit rrf serdata,f ;Rotate right moves data bits into
008C 000279 ;carry, starting with bit 0.
008C 000280
008C 0603 000281 btfsc c ;clear TXD if carry bit is set
008D 0447 000282 bcf TXD
008E 0703 000283 btfss c ;set TXD if carry bit is clear
008F 0547 000284 bsf TXD
0090 000285
0090 000286
0090 000287
0090 09A6 000288 call bitdelay ;Data bit.
0091 000289
0091 02EB 000290 decfsz bitcntr,f ;Not eight bits yet? Send next data bit
0092 0A8B 000291 goto xmit
0093 000292
0093 0447 000293 bcf TXD ;clear TXD
0094 032C 000294 rrf serdata,f ;last rotation
0095 000295
0095 000296
0095 09A6 000297 call bitdelay ;Stop bit. ((delay * 4) + 4) cycles
0096 000298
0096 0800 000299 retlw 0
0097 000300
0097 000301
0097 000302
0097 0727 000303 receive_byte btfss RXD
0098 0A97 000304 goto receive_byte ;wait until startbit
0099 000305
0099 0C08 000306 movlw 8h ;Eight bits in a byte.
009A 002B 000307 movwf bitcntr
009B 000308
009B 09AC 000309 call halfbitdelay ;wait half bit
009C 000310
009C 000311
009C 09A6 000312 rcb call bitdelay ;wait one bit
009D 000313
009D 0627 000314 btfsc RXD ;clear c if RXD is set
009E 0403 000315 bcf c
009F 0727 000316 btfss RXD ;set c if RXD is clear
00A0 0503 000317 bsf c
00A1 000318
00A1 032C 000319 rrf serdata,f
00A2 000320
00A2 02EB 000321 decfsz bitcntr,f ;Not eight bits yet? Receive next data bit
00A3 0A9C 000322 goto rcb
00A4 000323
00A4 09AC 000324 call halfbitdelay ;wait one half bit to get out of data area
00A5 000325
00A5 0800 000326 retlw 0
00A6 000327
00A6 000328
00A6 000329 ; To change the baud rate, substitute a new value for bitdelay at the beginning of
00A6 000330 ; this program.
00A6 000331
00A6 000332
00A6 000333
00A6 0C0F 000334 bitdelay movlw delay ;this bitdelay delays ((delay * 4) + 4) cycles
00A7 002A 000335 movwf delaycntr
00A8 0000 000336 :loop nop
00A9 02EA 000337 decfsz delaycntr,f
00AA 0AA8 000338 goto :loop ;this is an local loop
00AB 0800 000339 retlw 0
00AC 000340
00AC 000341
00AC 000342
00AC 0C08 000343 halfbitdelay movlw delay/2 +1 ;this bitdelay delays ((delay * 4) + 4)/2 cycles
00AD 002A 000344 movwf delaycntr
00AE 0000 000345 :loop nop
00AF 02EA 000346 decfsz delaycntr,f
00B0 0AAE 000347 goto :loop ;this is an local loop
00B1 0800 000348 retlw 0
00B2 000349
00B2 000350
00B2 000351
00B2 000352
07FF 000353 org 7ff
07FF 0A00 000354 goto start
Used Symbols
-----------------------------------------
pc 00000002
RA 00000005
RB 00000006
RC 00000007
ram 00000008
count0 00000008
count1 00000009
delaycntr 0000000A
bitcntr 0000000B
serdata 0000000C
serbuf 0000000D
charcounter 0000000E
clockspeed 00A8C000
baudrate 00009600
delay 0000000F
start 00000000
loop 00000011
command0 00000029
command1 0000002D
command2 00000031
command3 00000032
command4 00000033
command5 0000003A
command6 00000041
command7 00000041
command8 00000042
command9 00000046
commandA 0000004A
commandB 0000004E
commandC 0000004E
commandD 0000004E
commandE 0000004E
commandF 0000004F
string 00000058
send_byte 00000087
xmit 0000008B
receive_byte 00000097
rcb 0000009C
bitdelay 000000A6
halfbitdelay 000000AC
Used Defines
-----------------------------------------
beta
c 03h,0
z 03h,2
dc 03h,1
pd 03h,3
to 03h,4
RXD RC,1
TXD RC,2
pa0 03h,5
pa1 03h,6
PROGRAM MEMORY USAGE TABLE: '-' = not used 'X' = used
0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XX--------------
00C0 : ---------------- ---------------- ---------------- ----------------
0100 : ---------------- ---------------- ---------------- ----------------
0140 : ---------------- ---------------- ---------------- ----------------
0180 : ---------------- ---------------- ---------------- ----------------
01C0 : ---------------- ---------------- ---------------- ----------------
0200 : ---------------- ---------------- ---------------- ----------------
0240 : ---------------- ---------------- ---------------- ----------------
0280 : ---------------- ---------------- ---------------- ----------------
02C0 : ---------------- ---------------- ---------------- ----------------
0300 : ---------------- ---------------- ---------------- ----------------
0340 : ---------------- ---------------- ---------------- ----------------
0380 : ---------------- ---------------- ---------------- ----------------
03C0 : ---------------- ---------------- ---------------- ----------------
0400 : ---------------- ---------------- ---------------- ----------------
0440 : ---------------- ---------------- ---------------- ----------------
0480 : ---------------- ---------------- ---------------- ----------------
04C0 : ---------------- ---------------- ---------------- ----------------
0500 : ---------------- ---------------- ---------------- ----------------
0540 : ---------------- ---------------- ---------------- ----------------
0580 : ---------------- ---------------- ---------------- ----------------
05C0 : ---------------- ---------------- ---------------- ----------------
0600 : ---------------- ---------------- ---------------- ----------------
0640 : ---------------- ---------------- ---------------- ----------------
0680 : ---------------- ---------------- ---------------- ----------------
06C0 : ---------------- ---------------- ---------------- ----------------
0700 : ---------------- ---------------- ---------------- ----------------
0740 : ---------------- ---------------- ---------------- ----------------
0780 : ---------------- ---------------- ---------------- ----------------
07C0 : ---------------- ---------------- ---------------- ---------------X
Program Memory Words Used: 0179
Program Memory Words Free: 1869
Errors: 0